#ifndef _DNS_H_
#define _DNS_H_


#include "stdafx.h"
#include <event2/event.h>
#include <event2/dns.h>
#include <event2/thread.h>
#include <event2/dns_compat.h>



typedef void(*dns_func_cb)(int errcode,void *pdata, void* req, const char* ip);

typedef void(*dns_thread_cb)(int istart,void *pdata);


typedef struct dns_s dns_t;

struct dns_s {
	void*					data;
	struct	event_base*		base;
	struct	evdns_base*		dnsbase;
	int						irun;
	struct	timeval			watchtime;
	struct	event*			watchevent;
	dns_thread_cb			cb;
	struct event*			time_ev;

};

int dns_init(dns_t* dns, dns_thread_cb func, void* pdata);
int dns_free(dns_t* dns);
int dns_addaddress(dns_t* dns, const char* addr);


typedef struct dns_req_s dns_req_t;

struct dns_req_s {
	void* data;
	char* url;
	char* name;
	dns_func_cb func;
	dns_func_cb end;
	void* cb;
	struct	evdns_request*	handle;
	struct	evdns_base*		dnsbase;
};

int dns_req(dns_t* dns, dns_req_t* req);
int dns_canecl_req(dns_req_t* req);
int runloop(dns_t* dns);


#endif
